<?php
include('includes/connection_settings.php');

if (!isset($_COOKIE['username'])) {
 echo("Log in first!");
 exit;
}

//Strips " and ' marks
$bannedMarks = array("\"", "'");

$_GET['dictionary'] = str_replace($bannedMarks, "", $_GET['dictionary']);
$_COOKIE['username'] = str_replace($bannedMarks, "", $_COOKIE['username']);

if ($_GET['f'] == "add") {
 $table = mysql_query("UPDATE choices SET {$_COOKIE['username']} = true WHERE dictionary = '{$_GET['dictionary']}'");

 if (!isset($table)) {
  echo "<h1>Can't choose data from the table!</h1><p>" . mysql_error($connection) . "</p>";
  exit;
 }

 echo "<p><b>" . $_GET['dictionary'] . "</b> selected!</p>";

}

elseif ($_GET['f'] == "remove") {
 $table = mysql_query("UPDATE choices SET {$_COOKIE['username']} = false WHERE dictionary = '{$_GET['dictionary']}'");

 if (!isset($table)) {
  echo "<h1>Can't choose data from the table!</h1><p>" . mysql_error($connection) . "</p>";
  exit;
 }

 echo "<p><b>" . $_GET['dictionary'] . "</b> unselected!</p>";

}

mysql_close($connection);
?>